
/**
 * 定义：AssignmentExpression 节点表示赋值表达式。
 */


const code = `x = 10;`;

const ast = parser.parse(code);

// 定义 visitor
const visitor = {
    AssignmentExpression(path) {
        console.log(`Found Assignment: ${path.node.left.name} = ${path.node.right.value}`);
        path.node.right.value = 20; // 修改赋值的右侧值
    }
};

// 遍历 AST
traverse(ast, visitor);

// 生成新的代码
const { code: transformedCode } = generate(ast);
console.log(transformedCode);